package com.lcw.lostandfound.controller.backstage;

import com.alibaba.fastjson.JSON;
import com.lcw.lostandfound.pojo.Admin;
import com.lcw.lostandfound.pojo.Notice;
import com.lcw.lostandfound.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ANoticesController {
    @Autowired
    private NoticeService noticeService;

    @RequestMapping("/backstage/notices")
    public String goods(Model model, @RequestParam(name = "pageNum",required = false,defaultValue = "1")Integer pageNum, @RequestParam(name = "pageSize",required = false,defaultValue = "10")Integer pageSize){
        model.addAttribute("notices",noticeService.listNotices(pageNum,pageSize));
        return "admin/notice";
    }
    @ResponseBody
    @RequestMapping("/queryNotice")
    public String queryAdmin(Integer id){
        Notice notice = noticeService.queryNoticeById(id);
        System.out.println(JSON.toJSONString(notice));
        return JSON.toJSONString(notice);
    }
    @ResponseBody
    @RequestMapping("/deleteNotice")
    public String deleteGoods(Integer id){
        if (noticeService.deleteNotice(id)>0) {
            return "true";
        }
        return "false";
    }
    @ResponseBody
    @RequestMapping("/updateNotice")
    public String updateAdmin(Notice notice){
        if (noticeService.updateNotice(notice)>0){
            return "true";
        }
        return "false";
    }
    @ResponseBody
    @RequestMapping("/addNotice")
    public String addNotice(Notice notice){
        if (noticeService.insertNotice(notice)>0) {
            return "true";
        }
        return "false";
    }
}
